package com.cjjd.c.utils;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;


/**
 * ----------------------------------
 * Created by xyd on 2017/3/16.
 * <p/>
 * 描  述：
 * <p/>
 * 修订历史:
 * ----------------------------------
 */

public class FragmentUtil {

    /**
     * @param mContext  // fragmentActivity
     * @param fragment  // fragment
     * @param container // for example：R.id.fragment_container
     */
    public static void replaceWithAddToBack(FragmentActivity mContext, Fragment fragment, int container) {
        FragmentTransaction transaction = mContext.getSupportFragmentManager().beginTransaction();
        transaction.addToBackStack(null);
        transaction.replace(container, fragment);
        transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        transaction.commit();
    }

    /**
     * @param mContext  // fragmentActivity
     * @param fragment  // fragment
     * @param container // for example：R.id.fragment_container
     */
    public static void replaceWithoutAddToBack(FragmentActivity mContext, Fragment fragment, int container) {
        FragmentTransaction transaction = mContext.getSupportFragmentManager().beginTransaction();
        transaction.replace(container, fragment);
        transaction.commit();
    }
}
